import request from "./request";

const http = {
  // get请求
  get(url, params) {
    const config = {
      method: "GET",
      url: url,
      params: params ? params : {},
      headers: { "request-ajax": true },
    };
    return request(config);
  },

  // post请求 ----> json格式
  post(url, data) {
    const config = {
      method: "POST",
      url: url,
      data: data ? data : {},
      headers: { "Content-Type": "application/json", "request-ajax": true },
    };
    return request(config);
  },

  // post请求 ----> form-data格式, 既可以上传键值对，也可以上传文件
  upload(url, data) {
    const config = {
      method: "POST",
      url: url,
      data: data ? data : {},
      headers: { "Content-Type": "multipart/form-data", "request-ajax": true },
    };
    return request(config);
  },

  // put请求
  put(url, data) {
    const config = {
      method: "PUT",
      url: url,
      data: data ? data : {},
      headers: { "Content-Type": "application/json", "request-ajax": true },
    };
    return request(config);
  },

  // delete请求
  delete(url, params) {
    const config = {
      method: "DELETE",
      url: url,
      params: params ? params : {},
      headers: { "request-ajax": true },
    };
    return request(config);
  },
};

export default http;
